<?php

namespace common\dao\dd;

/**
 * 城市代码
 * 
 * @author peng.huang
 */
class CityDao extends DdDao {

    /**
     * 表名
     * 
     * @var string 
     */
    public $table = 's_city';

    /**
     * 获取城市数据
     * 
     * @param bool $isFlip [是否键与值交换]
     * @param string|int $code [代码]
     * @return mixed
     */
    public function get($isFlip = TRUE, $code = NULL) {
        $func = function () {
            $data = $this->findAll('code,name');
            $text = '';
            foreach ($data as $value) {
                $text .= sprintf('\'%s\'=>\'%s\',', $value ['code'], $value ['name']) . PHP_EOL;
            }

            unset($data);
            return $text;
        };

        return $this->_getDD('city', $func, $isFlip, $code);
    }

}
